package com.xmy.cultivate.mapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.xmy.cultivate.entity.*;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * <p>
 * 排课表 Mapper 接口
 * </p>
 *
 * @author min
 * @since 2022-07-28
 */
public interface CourseSchedulingMapper extends BaseMapper<CourseScheduling> {
    @Select("select * from course_scheduling ${ew.customSqlSegment}")
    public abstract List<CourseScheduling> getCourseScheduling(@Param(Constants.WRAPPER) QueryWrapper queryWrapper);

    @Select({"<script>",
            "select student_id as id,1 as course_type,student_grade.school_id  ",
            "from student_grade ",
            "LEFT JOIN student ON student.id = student_grade.student_id ",
            "where ",
            "student_grade.STATUS = 1 ",
            "AND reading_status = 1 ",
            "AND student_grade.deleted = 0 ",
            "AND student_grade.grade_id = #{gradeId} ",
            "<when test='studentName!=null and studentName!=&apos;&apos;'>",
            "AND student.`name` like '%${studentName}%' ",
            "</when>",
            "AND student_id not in(select student_id from repair_course where deleted = 0 and out_scheduling_detail_id = #{schedulingDetailId}) ",
            "UNION ",
            "select student_id as id,1 as course_type,school_id from repair_course where deleted = 0 and scheduling_detail_id = #{schedulingDetailId} ",
            "</script>"})
    public abstract List<Student> getStudentForSchedulingGrade(@Param("gradeId") Long gradeId,@Param("schedulingDetailId") Long schedulingDetailId,@Param("studentName") String studentName);
}
